<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge，chrome=1">
    <meta name="renderer" content="webkit">
    <script src="../../../node_modules/jquery/dist/jquery.min.js"></script>
    <link rel="stylesheet" href="../../../node_modules/bootstrap/dist/css/bootstrap.min.css">
    <script src="../../../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="../../../node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="../../../node_modules/vue/dist/vue.min.js"></script>
    <link rel="stylesheet" href="../../../node_modules/element-ui/lib/theme-chalk/index.css">
    <script src="../../../node_modules/element-ui/lib/index.js"></script>
    <script src="../../../node_modules/echarts/dist/echarts.js"></script>


    <!-- 自定义 -->
    <script src="../../../node_modules/mockjs/dist/mock.js"></script>
    <script src="../static/js/mock_config.js"></script>
    <script src="../static/js/index.js"></script>
    <link rel="stylesheet" href="../../index.css">

    <!-- PC -->
    <link rel="stylesheet" href="../static/css/TradeSales.css" media="only screen and (max-height:1600px) ">
    <!-- 手机App -->
    <link rel="stylesheet" href="../static/css/TradeSalesApp.css" media="only screen and (min-height:1600px) ">

</head>

<body>
    <!--主体-->
    <div class="main clearfix" id="app">
        <div class="header" style="padding-top: 25px; ">
            <header>
                <div class="navbar">
                    <div class="card A">
                        <ul class="header-text">
                            <li>
                                <h8 style="line-height: 78px;">贸易看板</h8>
                            </li>
                        </ul>

                    </div>
                    <div class="card B">
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item">
                                <h4>客户</h4>
                            </li>
                            <li class="list-group-item1">
                                <h3 id="Client">0
                                </h3>
                            </li>
                        </ul>
                    </div>
                    <div class="card C">
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item">
                                <h4>本月订单</h4>
                            </li>
                            <li class="list-group-item1">
                                <h3 id="MothOrder">0</h3>
                            </li>
                        </ul>
                    </div>
                    <div class="card C">
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item">
                                <h4>本年订单</h4>
                            </li>
                            <li class="list-group-item1">
                                <h3 id="YearOrder">0</h3>
                            </li>
                        </ul>
                    </div>
                    <div class="card D">
                        <ul class="list-group list-group-flush">
                            <li class="list-group-item">
                                <h4>上月同比增长率</h4>
                            </li>
                            <li class="list-group-item1">
                                <h3 id="LastMonthOrderAmtYOY">{{LastMonthOrderAmtYOY}}%</h3>
                            </li>
                        </ul>
                    </div>
                </div>
            </header>
        </div>

        <div class="body_div">
            <div class="main-left">
                <div class="border-container3">
                    <div class="name-title">
                        订单额同比
                    </div>
                    <div>
                        <div id="echarts1"></div>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
                <div class="border-container3">
                    <div class="name-title">
                        客户排行榜（前10）
                    </div>
                    <div>
                        <el-table :data="defaultDt1" :default-sort="{prop: 'date', order: 'descending'}" stripe="true" ref="defaultDt1" :height=el_table_height4 :cell-style="{padding:3+'px'}">
                            <el-table-column type="index" width="50" label="序号">
                            </el-table-column>
                            <el-table-column prop="ClientCode" align="center" label="客户">
                            </el-table-column>
                            <el-table-column align="center" label="占比排名">
                                <template slot-scope="scope">
                                    <div v-html="Kecutout(scope)">
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
            </div>
            <div class="center">
                <div class="border-container3">
                    <div class="name-title">
                        订单走势
                    </div>
                    <div>
                        <div id="echarts2" style="width:100%;height: 430px;"></div>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>

                <div class="border-container3">
                    <div class="name-title">
                        送货及月度毛利
                    </div>
                    <div>
                        <div id="echarts3" style="height: 400px; width: 100%;"></div>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
            </div>
            <div class="main-right">
                <div class="border-container3">
                    <div class="name-title">
                        单个产品利润排行
                    </div>
                    <div>
                        <el-table :data="defaultDt2" :default-sort="{prop: 'date', order: 'descending'}" stripe="true" ref="defaultDt2" :height=el_table_height4 :cell-style="{padding:3+'px'}">
                            <el-table-column type="index" width="50" label="序号">
                            </el-table-column>
                            <el-table-column prop="GoodsName" align="center" label="产品名称">
                            </el-table-column>
                            <el-table-column prop="UnitGrossProfit" align="center" label="单位毛利润">
                            </el-table-column>
                            <el-table-column prop="GrossProfit" align="center" label="毛利润率">
                            </el-table-column>
                        </el-table>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
                <div class="border-container3">
                    <div class="name-title">
                        产品总利润排行
                    </div>
                    <div>
                        <el-table :data="defaultDt3" :default-sort="{prop: 'date', order: 'descending'}" stripe="true" ref="defaultDt3" :height=el_table_height4 :cell-style="{padding:3+'px'}">
                            <el-table-column type="index" width="50" label="序号">
                            </el-table-column>
                            <el-table-column prop="GoodsName" align="center" label="产品名称">
                            </el-table-column>
                            <el-table-column prop="SendAmt" align="center" label="出货额">
                            </el-table-column>
                            <el-table-column prop="GrossProfit" align="center" label="利润额">
                            </el-table-column>
                        </el-table>
                    </div>
                    <span class="top-left border-span"></span>
                    <span class="top-right border-span"></span>
                    <span class="bottom-left border-span"></span>
                    <span class="bottom-right border-span"></span>
                </div>
            </div>
        </div>
    </div>

</body>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                el_table_height4: 422,
                echarts1: null,
                echarts2: null,
                echarts3: null,
                defaultDt1: [],
                defaultDt2: [],
                defaultDt3: [],
                LastMonthOrderAmtYOY:0,
                option2: {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            crossStyle: {
                                color: '#999'
                            }
                        }
                    },
                    legend: {
                        textStyle: {
                            color: '#00FFFFF'
                        }
                    },
                    xAxis: {
                        type: 'category',
                        color: 'white',
                        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                        axisPointer: {
                            type: 'shadow'
                        },
                        axisLabel: {
                            textStyle: {
                                color: "#FFF"
                            }
                        },
                    },
                    yAxis: {
                        type: 'value',
                        axisLabel: {
                            formatter: '{value} (万元)',
                            textStyle: { //改变xy轴上文字的颜色
                                color: "#FFF"
                            }
                        }
                    },
                    series: [{
                        data: [],
                        type: 'bar',
                        itemStyle: { //上方显示数值
                            normal: {
                                label: {
                                    show: true, //开启显示
                                    position: 'top', //在上方显示
                                    textStyle: { //数值样式
                                        color: 'white'
                                    }
                                }
                            }
                        }
                    }]
                },
                option3: {
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'cross',
                            crossStyle: {
                                color: '#999'
                            }
                        }
                    },
                    legend: {
                        textStyle: {
                            color: '#00FFFFF'
                        }
                    },
                    xAxis: [{
                        type: 'category',
                        color: 'white',
                        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
                        axisPointer: {
                            type: 'shadow'
                        },
                        axisLabel: {
                            textStyle: {
                                color: "#FFF"
                            }
                        },
                    }],
                    yAxis: [{
                        type: 'value',
                        axisLabel: {
                            formatter: '{value}',
                            textStyle: { //改变xy轴上文字的颜色
                                color: "#FFF"
                            }
                        }
                    }, {
                        type: 'value',
                        min: 0,
                        splitLine: {
                            //不显示分割线
                            show: false
                        },
                        axisLabel: {
                            formatter: '{value}',
                            textStyle: { //改变xy轴上文字的颜色
                                color: "#FFF"
                            }
                        }
                    }],
                    series: [{
                        type: 'bar',
                        data: [],
                        itemStyle: { //上方显示数值
                            normal: {
                                label: {
                                    show: true, //开启显示
                                    formatter: function(params) {
                                        if (params.value > 0) {
                                            return params.value;
                                        } else {
                                            return '';
                                        }
                                    },
                                    position: 'top', //在上方显示
                                    textStyle: { //数值样式
                                        color: 'white'
                                    }
                                }
                            }
                        }
                    }, {
                        type: 'line',
                        yAxisIndex: 1,
                        data: [],
                        itemStyle: {
                            normal: {
                                label: {
                                    formatter: function(params) {
                                        if (params.value > 0) {
                                            return params.value;
                                        } else {
                                            return '';
                                        }
                                    },
                                    show: true,
                                    color: "#FFF"
                                }
                            }
                        }
                    }]
                },
            }
        },
        methods: {
            GetTabelDate(that) {
                //客户
                GetCodeData("VB21103014024226", "Get", "Goods").then(function(res) {
                        $('#Client').text("" + res.rows[0].number + "家")
                    }),
                    //本月订单
                    GetCodeData("VB21102911392496", "Get", "Goods").then(function(res) {
                        $('#MothOrder').text("" + res.rows[0].Total + "万元")
                    }),
                    //本年订单
                    GetCodeData("VB21102911401970", "Get", "Goods").then(function(res) {
                        $('#YearOrder').text("" + res.rows[0].Total + "万元")
                    }),
                    //同比增长率
                    GetCodeData("VB21112011364760", "Get", "Goods").then(function(res) {
                        // $('#GrowthRate').text("" + res.rows[0].TaxAmtOrd + "%")
                        that.LastMonthOrderAmtYOY=res.rows[0].LastMonthOrderAmtYOY;
                    }),
                    //订单额同比
                    GetCodeData("VB21111613590836", "Get", "Goods").then(function(res) {
                        //柱状图
                        var chartDom = document.getElementById('echarts1');
                        var myChart = echarts.init(chartDom);
                        var xAxisData = []; //X轴数据
                        var seriesData = []; //系列数据

                        if (res.rows != null && res.rows.length > 0) {
                            for (var i = 0; i < res.rows.length; i++) {
                                xAxisData.push(res.rows[i]["DeliveryYear"]);
                                seriesData.push(res.rows[i]["TaxAmtDelivery"]);
                            }
                        }
                        var option = {
                            xAxis: {
                                type: 'category',
                                data: xAxisData
                            },
                            yAxis: {
                                type: 'value'
                            },
                            series: [{
                                data: seriesData,
                                type: 'bar',
                                label: {
                                    show: true,
                                    position: 'top',
                                    textStyle: { //数值样式
                                        color: 'white',
                                        fontSize:12
                                    },
                                    formatter: function(params) {
                                        if (params.value > 0) {
                                            return params.value;
                                        } else {
                                            return '';
                                        }
                                    }
                                }
                            }]
                        };

                        myChart.setOption(option);
                    }),
                    //客户排行榜
                    GetCodeData("VB21102909460158", "Get", "Goods").then(function(res) {
                        that.defaultDt1 = res.rows
                    }),
                    //订单走势
                    GetCodeData("VB21102909474636", "Get", "Goods").then(function(res) {
                        var 订单走势 = []
                        res.rows.forEach(element => {
                            Object.values(element).forEach(item => {
                                if (element.type == "订单走势") {
                                    if (typeof(item) == "number") {
                                        订单走势.push(item)
                                    }
                                }
                            })
                        })
                        that.option2.series[0].data = 订单走势;
                        that.echarts2.setOption(that.option2);
                    }),
                    //送货及月度毛利
                    GetCodeData("VB21111616042640", "Get", "Goods").then(function(res) {
                        var 送货金额 = []
                        var 毛利润 = []
                        res.rows.forEach(element => {
                            Object.values(element).forEach(item => {
                                if (element.type == "送货金额") {
                                    if (typeof(item) == "number") {
                                        送货金额.push(item)
                                    }
                                } else {
                                    if (typeof(item) == "number") {
                                        毛利润.push(item)
                                    }
                                }
                            })
                        })

                        that.option3.series[0].data = 送货金额;
                        that.option3.series[1].data = 毛利润;
                        that.echarts3.setOption(that.option3);

                    }),
                    //单个产品利润排行榜
                    GetCodeData("VB21111714422698", "Get", "Goods").then(function(res) {
                        that.defaultDt2 = res.rows

                    }),
                    //产品利润排行榜
                    GetCodeData("VB21111714425169", "Get", "Goods").then(function(res) {
                        that.defaultDt3 = res.rows
                    })
            },
            //客户排行
            Kecutout(cellValue) {
                let _html = "";
                if (cellValue) {
                    _html += "<div>"
                    var _width1 = 100;
                    var _color = "";
                    _width1 = cellValue.row.TaxAmtOrd * 100 / cellValue.row.ToTal;
                    if (_width1 > 100) {
                        _width1 = 100;
                    }
                    if (cellValue.row.TaxAmtOrd < cellValue.row.ToTal) {
                        _color = "#00a000";
                    } else if (cellValue.row.TaxAmtOrd > cellValue.row.ToTal) {
                        _color = "#FF0000";
                    } else {
                        _color = "#008000";
                    }

                    _html += ("<div  style='position: relative; width:120px;padding: 0px;background:#4199fe;overflow: hidden;height:27px;border: 1px solid #95b8e7;'><div style='width: " + _width1 + "%; display: block; position: relative; background: " + _color + "; color: #000; height: 40px; line-height: 40px;'>" +
                        "</div>" +
                        "<div style='position:absolute;width:100%;height:100%;top:0;display:flex;align-items:center;justify-content:center;color:black;'>" + cellValue.row.percentage + "%" + "</div>" +
                        "</div>" +
                        "");
                    return _html;
                }
            },
        },

        mounted() {
            TableAotoRoll([this.$refs.defaultDt1, this.$refs.defaultDt2, this.$refs.defaultDt3])
            var that = this
            setTimeout(function() {
                that.echarts2 = echarts.init(document.getElementById('echarts2')),
                    that.GetTabelDate(that);
                that.echarts3 = echarts.init(document.getElementById('echarts3')),
                    that.GetTabelDate(that);
            }, 0);
            setInterval(function() {
                that.GetTabelDate(that)
            }, 1000 * 60);
        }
    })
</script>



</html>